(function($){
	//faux select class
	this.FauxSelect = new Class({

		//implements
		Implements: [Options,Events],

		//options
		options: {
			cssPrefix: 'FS-',
			triggerText: 'Select Something',
			triggerEvent: 'click',
			triggerElement: $empty(),
			onChange: $empty()
		},

		//initialization
		initialize: function(elements,options) {
			//set options
			this.setOptions(options);
			//set elements
			this.elements = $$(elements);
			//apply to default elements
			this.elements.each(function(el){
				this.apply(el);
			},this);
		},

		//applies the Faux look to every desired element
		apply: function(element) {
			//settings and shortcut vars
			var c = this.options.cssPrefix;
			
			//create the replacement DIV container
			var container = new Element('div',{
				id: c + 'Container'
			}).inject($(document.body), 'bottom');//.replaces(element);
			//element.destroy();
			
			//create a hidden input with the same name to store the value
			var input = new Element('input',{
				value: '',
				type: 'hidden',
				name: element.get('name'),
				id: element.get('id')
			}).inject(container);
			
			//provide the "trigger"
			if(this.options.triggerElement != $empty()){
				var trigger = this.options.triggerElement;
			}
			else {
				var trigger = new Element('span',{
					text: this.options.triggerText,
					id: c + 'Trigger'
				}).inject(container);
			}
			
			//provide the list
			var list = new Element('ul',{
				id: c + 'Selector'
			}).inject(container);
			
			//inject the options into the list
			element.getElements('option').each(function(option){
				var li = new Element('li',{
					text: option.get('text'),
					'class': (option.selected ? 'Selected' : '')
				}).inject(list);
				li.store('value',option.get('value'));
				if(option.selected) { input.value = option.value; }
			});
			
			//create the replacement elements
			var FSHideLayer = new Element('div', {
			    'id': c + 'HideLayer',
			    'html': '&nbsp;',
				'events': {
			        'click': function(){
						$$(this,list).removeClass('Visible');
			        }
			    }
			});
			var nwShadow = new Element('div', {'id': c + 'NW', 'class': 'Shadow', 'html': '&nbsp;'});
			var nShadow = new Element('div', {'id': c + 'N', 'class': 'Shadow', 'html': '&nbsp;'});
			var neShadow = new Element('div', {'id': c + 'NE', 'class': 'Shadow', 'html': '&nbsp;'});
			var eShadow = new Element('div', {'id': c + 'E', 'class': 'Shadow', 'html': '&nbsp;'});
			var seShadow = new Element('div', {'id': c + 'SE', 'class': 'Shadow', 'html': '&nbsp;'});
			var sShadow = new Element('div', {'id': c + 'S', 'class': 'Shadow', 'html': '&nbsp;'});
			var swShadow = new Element('div', {'id': c + 'SW', 'class': 'Shadow', 'html': '&nbsp;'});
			var wShadow = new Element('div', {'id': c + 'W', 'class': 'Shadow', 'html': '&nbsp;'});
			var ShadowParts = new Array(nwShadow, nShadow, neShadow, eShadow, seShadow, sShadow, swShadow, wShadow);
			
			//Inject the created elements
			FSHideLayer.inject(container, 'after');
			ShadowParts.each(function(el){
				el.inject(list, 'top');
			});

			//The "trigger" and "hide" events
			trigger.addEvent(this.options.triggerEvent, function(e){
					e.preventDefault();
					if(trigger.hasClass('searchClear'))
						return false;
					dim = this.options.triggerElement.getCoordinates();
					container.setPosition({x: (dim.left-dim.width), y: (dim.top + dim.height)});
					$$(FSHideLayer,list).addClass('Visible');	
			}.bind(this));
			
			var ez = this;

			//What to do when each link is clicked
			var listItems = list.getElements('li');
			listItems.each(function(FSLink){
				FSLink.addEvent('click', function(e){
				    e.preventDefault(); //Prevents the browser from following the link.
					listItems.removeClass('Selected');
					this.addClass('Selected');
					var FSLinkId = this.getProperty('id');
					$$(FSHideLayer,list).removeClass('Visible');
					//This is where you do something with the returned ID for the selected item...
					ez.fireEvent('change', new Array(FSLink.retrieve('value'), FSLink.get('text')));
					input.value = FSLink.retrieve('value');
				});
			});
			element.dispose();
		}
		
	});
	
	//usage
	/*window.addEvent('domready',function(){
		var FS = new FauxSelect('.faux');
	});*/
})(document.id);